#{extends 'main.html' /}
#{set title:'Add Activity' /}

<script>
    function submitF() {
        $("#form").submit();
    }
    
    
</script>

<h2> Add Activities </h2>

<form id ="form" action="@{Application.addTeacherActivity()}" method="POST">
    Select a teacher <select size="1" name="teacher_id" id = "t_id" onchange="submitF()" > 
            <option value="">--</option>
            #{list items:teachers, as:'su'}
            #{if su.id == teacher_id}
                <option selected="selected" value="${su.id}">${su.name}</option>
                #{/if}
                #{else}
                 <option value="${su.id}">${su.name}</option>
                #{/else}
            #{/list}
           </select>
</form>

<br>

#{if teacher_id != null }
#{if !teacher_activities.isEmpty()}
<h2> Currently Teaching </h2>
 			<ul>
 			#{list items:teacher_activities, as:'a'}
             <li>${a.name}</li>
            #{/list}
            </ul>
            <br>
#{/if}

#{else}
<h2 style="color: red;"> No Activity assigned yet ! </h2>
#{/else}

#{if activities.isEmpty()}
<h2 style="color: red;">No activities to add !</h2>
#{/if}
#{else}
<form id ="form2" action="@{Application.addTeacherActivity()}" method="POST">       
    
     <input type="hidden" id = "te_id" name = "teacher_id">
     
     <script type="text/javascript">
     $("#te_id").val(''+($("#t_id").val()));
     </script>
     
     Select an Activity <select size="1" name="activity_id"> 
                <option value="">--</option>
            #{list items:activities, as:'a'}
                <option value="${a.id}">${a.name}</option>
            #{/list}
           </select>&nbsp;&nbsp;&nbsp; <input type="submit" value="Add Activity"/>
</form>
<br>
#{/else}
#{/if}
